package com.hzhc.controller.zk;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.common.BaseController;
import com.hzhc.dto.UserDto;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.CntrInfoService;
import com.hzhc.service.DeclareCarService;
import com.hzhc.service.VehicleReservationService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.CntrInfoVo;
import com.hzhc.vo.CntrTallyVo;
import com.hzhc.vo.DeclareCarVo;
import com.hzhc.vo.VehicleReservationVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 中控理货
 *
 * @author 功不唐捐
 * @since 2024-06-01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/zkPlan")
public class ZkPlanController extends BaseController {
    private final DeclareCarService declareCarService;

    private final CntrInfoService cntrInfoService;

    private final VehicleReservationService vehicleReservationService;

    /**
     * 查询卡口数据
     */
    @RequestMapping("/getGateCarList")
    public ResultUtil<List<DeclareCarVo>> getGateCarList(@RequestBody DeclareCarVo vo) {
        Page<DeclareCarVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<DeclareCarVo> declareCarVos = declareCarService.getZkTodayRcCarList(page, vo);
        return ResultUtil.build(declareCarVos,page.getTotal(),page.getPages(),ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 中控理货
     */
    @PostMapping("/cntrDuiTally")
    public ResultUtil<T> cntrDuiTally(@RequestBody CntrTallyVo vo, HttpServletRequest request) {
        UserDto user = TokenUtil.getUser(request);
        vo.setUid(user.getId());
        vo.setUserName(user.getRealname());
        vo.setAccesspath("PC端");
        return  cntrInfoService.cntrDuiTally(vo);
    }

    /**
     * 提箱理货
     */
    @PostMapping("/cntrTxTally")
    public ResultUtil<T> cntrTxTally(@RequestBody DeclareCarVo vo, HttpServletRequest request) {
        UserDto user = TokenUtil.getUser(request);
        vo.setAccesspath("PC端");
        vo.setUserId(user.getId());
        vo.setUserName(user.getRealname());
        return  declareCarService.updateCntrTxTallyNew(vo);
    }

    /**
     * 中控选择在场箱数据
     */
    @RequestMapping("/getZkCntrList")
    public ResultUtil<List<CntrInfoVo>> getZkCntrList(@RequestBody CntrInfoVo vo) {
        Page<CntrInfoVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<CntrInfoVo> cntrInfoVoList = cntrInfoService.getAllList(page, vo);
        return ResultUtil.build(cntrInfoVoList,page.getTotal(),page.getPages(),ResultUtilCodeEnum.SUCCESS);
    }


    /**
     * 中控理货 车辆预约数据
     */
    @RequestMapping("/getVehicleList")
    public ResultUtil<List<VehicleReservationVo>> getVehicleList(@RequestBody VehicleReservationVo vo) {
        Page<VehicleReservationVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<VehicleReservationVo> vehicleReservationVos = vehicleReservationService.getVehicleList(page, vo);
        return ResultUtil.build(vehicleReservationVos,page.getTotal(),page.getPages(),ResultUtilCodeEnum.SUCCESS);
    }
}
